﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Xml.Serialization;

namespace MazeWars
{
    [XmlRoot("trunk")]
    public class Trunk
    {
        
        List<Tile> trunkTiles;
        string name;
        int spellID;
        float cooldownTime;
        bool cooldown;
        Point offset;
        const float COOLDOWN_TIME = 10.0f;

        [XmlAttribute("cooldown")]
        public bool OnCooldown
        {
            set
            {
                cooldown = value;
            }
            get
            {
                return cooldown;
            }
        }

        public Point Offset
        {
            set
            {
                offset = value;
            }
            get
            {
                return offset;
            }
        }

        [XmlArray("tiles")]
        [XmlArrayItem("tile", typeof(Tile))]
        public List<Tile> TrunkTiles
        {
            set
            {
                trunkTiles = value;
            }
            get
            {
                return trunkTiles;
            }
        }

        [XmlAttribute("name")]
        public string Name
        {
            set
            {
                name = value;
            }
            get
            {
                return name;
            }
        }

        [XmlAttribute("spellid")]
        public int SpellID
        {
            set
            {
                spellID = value;
            }
            get
            {
                return spellID;
            }
        }

        public Trunk()
        {
            trunkTiles = new List<Tile>();
            offset = new Point(0, 0);
            name = "Default";
            spellID = -1;
            cooldown = false;
            cooldownTime = 0;
        }

        public Trunk(Trunk copy)
        {
            trunkTiles = copy.TrunkTiles;
            offset = copy.Offset;
            name = copy.Name;
            spellID = copy.SpellID;
            cooldown = false;
            cooldownTime = 0;
        }

        public void manageCooldown(GameTime gt)
        {
            cooldownTime += gt.ElapsedGameTime.Milliseconds / 1000.0f;
            if (cooldownTime >= COOLDOWN_TIME)
            {
                cooldown = false;
                cooldownTime = 0;
            }
        }
    }//End of class Trunk
}
